#define _CRT_SECURE_NO_WARNINGS 2

#include<stdio.h>
#include<stdbool.h>

void Swap(int* a, int* b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void SelectSort(int* a, int n) {
	int left = 0;
	int right = n - 1;
	while (left < right) {
		int maxi = left;
		int mini = maxi;
		for (int j = left+1; j < n-left; j++) {
			if (a[mini] > a[j]) {
				mini = j;
			}
			if (a[maxi] < a[j]) {
				maxi = j;
			}
		}
		Swap(&a[mini], &a[left]);
		if (left == maxi) {
			maxi = mini;
		}
		Swap(&a[maxi], &a[right]);
		++left;
		--right;
	}
	
}

int main() {
	int arr[] = { 1,2,3,4,5,32,43,-1,0,-21 };
	int len = sizeof(arr) / sizeof(arr[0]);
	SelectSort(arr, len);
	for (int i = 0; i < len; i++) {
		printf("%d ", arr[i]);
	}
	return 0;
}